package com.ycl.web.backend;

import com.github.pagehelper.Page;
import com.ycl.model.EbProduct;
import com.ycl.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 商品分页查询
     *
     * @param model
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping("/list")//分页查询商品数据
    public String list(Model model ,
                       @RequestParam(value = "page",defaultValue = "1")Integer page,
                       @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize){
        List<EbProduct> ebProducts = productService.list(page, pageSize);
        model.addAttribute("ebProducts",ebProducts);
        //2.1传递当前页到product.jsp
        model.addAttribute("curPage",page);
        //2.2传递最大页数到product.jsp
        model.addAttribute("maxPage",((Page)ebProducts).getPages());
        return "manage/product";
    }


}
